﻿using System;
using UnityEditor;
using UnityEngine;

namespace Script.Com.Enemy.EnemySystem.Tools
{
    public class ArchersArrow : MonoBehaviour
    {
        
        private Vector3 flyDirection;
        private bool getTarget;
        
        private float speed;
        

        private void Update()
        {

            if(getTarget)
                transform.position += flyDirection * (Time.deltaTime * speed);
            
        }

        public void SetTarget(Vector2 pos, float dir, float arrowSpeed)
        {
            flyDirection = (pos - (Vector2)transform.position).normalized;
            transform.Rotate(Vector3.forward, dir);
            getTarget = true;
            speed = arrowSpeed;
        }

        private void OnTriggerEnter2D(Collider2D other)
        {
            
            if(other.gameObject.CompareTag("Player"))
                Debug.Log("collision is Player");

            Destroy(gameObject);
        }
    }
}